package elin.blog;
import com.opensymphony.xwork2.ActionSupport;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class NewBlogAction extends ActionSupport {
	public String title;
	public String content;
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String execute() throws Exception{
		System.out.println("title:"+title);
		System.out.println("content:"+content);
//		System.out.println("date:"+System.currentTimeMillis());
		save();
		return SUCCESS;
	}
	public void save(){
		Configuration config=new Configuration().configure();
		SessionFactory sf=config.buildSessionFactory();
		Session session=sf.openSession();
		Transaction tx = session.beginTransaction();
		
		Blog blog=new Blog(title,content,System.currentTimeMillis()+"");
		
		session.save(blog);
		
		session.flush();
		tx.commit();
		session.close();
		sf.close();
		
	}
}
